class GenreateRights < ActiveRecord::Migration
  def self.up
  
	fillperm_id=SurveyPermissionType.find_by_name('fill').id
	editionperm_id=SurveyPermissionType.find_by_name('edition').id
	statsperm_id=SurveyPermissionType.find_by_name('stats').id
	
	
  	for user in User.find(:all)
	  	for survey in Survey.find(:all)		
	  		r=rand(2)
	  		if r==1
	  			x=rand(2)
	  			if x==0
	  				UsersSurveysPermission.create(:survey_id=>survey.id,:permission_type_id=>fillperm_id,:user_id=>user.id)
			
	  			end 
	  			if x==1 && user.access_level>=2 && user.id!=survey.user
	  				UsersSurveysPermission.create(:survey_id=>survey.id,:permission_type_id=>editionperm_id,:user_id=>user.id)
					UsersSurveysPermission.create(:survey_id=>survey.id,:permission_type_id=>statsperm_id,:user_id=>user.id)
				end 
	  		end
	  	end
  	end
  	
  end

  def self.down
  	UsersSurveysPermission.delete_all
  end
end
